package com.leyou.job.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisConfig {

    @Bean
    public RedissonClient redissonClient(RedisProperties prop) {
        // 字符串占位写法
        String address = "redis://%s:%d";
        //String address2 = "redis://localhost:6379";
        address = String.format(address, prop.getHost(), prop.getPort());
        // 创建Redisson客户端
        Config config = new Config();
        config.useSingleServer().setAddress(address);
        return Redisson.create(config);
    }
}